<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <input type="hidden" name="id" th:value="${user.id}" />
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username"  th:value="${user.username}" lay-verify="title" autocomplete="off" placeholder="请输入用户名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="text"  name="password" th:value="${user.password}" lay-verify="title" autocomplete="off" placeholder="请输入密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">salt</label>
                    <div class="layui-input-block">
                        <input type="text"  name="salt" th:value="${user.salt}" autocomplete="off" placeholder="请输入密码" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">账户状态</label>
                    <div class="layui-input-block">
                        <select id="status" name="status" class="valid">
                            <p th:if="${user.status == 0}">
                                <option value="0">正常</option>
                                <option value="1">其他</option>
                            </p>
                            <p th:if="${user.status == 1}">
                                <option value="1">其他</option>
                                <option value="0">正常</option>
                            </p>
                        </select>
                    </div>
                </div>


            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
layui.use(['form','jquery'],function(){
    let form = layui.form;
    let $ = layui.jquery;

    form.on('submit(user-save)', function(data){
        console.log(data.field);
        $.ajax({
            type: 'post', // 提交方式 get/post
            url: '/user/updateUser', // 需要提交的 url
            data: {
                id: $('input[name=id]').val(),
                username: $('input[name=username]').val(),
                password: $('input[name=password]').val(),
                salt: $('input[name=salt]').val(),
                status: $('#status').val()
            },
            // dataType:'json',
            // contentType:'application/json',
            success:function(result){
                layer.msg(result.message,{icon:1,time:500},function(){
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("user-table");
                });
            },
            error:function (result) {
                layer.msg(result.message,{icon:2,time:500},function(){
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("user-table");
                });
            }
        });
        return false; // 阻止表单自动提交事件，必须返回false，否则表单会自己再做一次提交操作，并且页面跳转


    });
})
</script>
<script>
</script>
</body>
</html>
